package com.handinfo.uimenu.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Vector;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.game.AbstractGameActor;
import com.handinfo.game.ActorNPC;
import com.handinfo.game.ActorRole;
import com.handinfo.game.Function;
import com.handinfo.game.GameScene;
import com.handinfo.game.Task;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIDialogMenu;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UIPalette;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.ArrayList;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;

public class UINPCWindow extends UIAbstractWindow
{

	public UINPCWindow(int id)
	{
		super(id);
		m_x = 0;
		m_y = 0;
		m_w = AbstractGameScreen.SCREEN_WIDTH;
		m_h = AbstractGameScreen.SCREEN_HEIGHT;
	}

	protected void paintContent(Graphics g)
	{
		switch (m_state) {
			case STATUS_NPC_LIST:
				break;
			case STATUS_SCENE_MAP:
				drawSceneMap(g);
				break;
			case STATUS_WORLD_MAP:
				drawWorldMap(g);
				break;
		}
	}

	private void drawWorldMap(Graphics g) {
		if (img_world_map != null) {
			g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
			g.setColor(Tools.BLACK);
			g.fillRect(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
			if (m_is_area_map) {
				
				int x = AREA_MAP_XY[m_world_map_index][(m_area_map_index << 1)];
				int y = AREA_MAP_XY[m_world_map_index][(m_area_map_index << 1) + 1];
				int offsetx = (AbstractGameScreen.SCREEN_WIDTH - 160) >> 1;
				int offsety = (AbstractGameScreen.SCREEN_HEIGHT - 180) >> 1;
				g.drawImage(img_world_map, offsetx, offsety, Tools.LEFT_TOP);
				if (img_world_index != null) {
					g.setClip(x + offsetx, y - WORLD_INDEX_H + offsety, WORLD_INDEX_W, WORLD_INDEX_H);
					g.drawImage(img_world_index, x - m_world_index_frame * WORLD_INDEX_W + offsetx, y - WORLD_INDEX_H + offsety, Tools.LEFT_TOP);
				}
			} else {
				int x = WORLD_MAP_XY[(m_world_map_index << 1)];
				int y = WORLD_MAP_XY[(m_world_map_index << 1) + 1];
				int offset = 0;
				//#if screen == "320240"
				//# if (y > (AbstractGameScreen.SCREEN_HEIGHT >> 2) * 3) {
				//# 	offset = 300 - AbstractGameScreen.SCREEN_HEIGHT;
				//# }
				//# g.drawImage(img_world_map, 10, 0 - offset, Tools.LEFT_TOP);
				//# if (img_world_index != null) {
				//# 	g.setClip(x + 10, y - WORLD_INDEX_H - offset, WORLD_INDEX_W, WORLD_INDEX_H);
				//# 	g.drawImage(img_world_index, x - m_world_index_frame * WORLD_INDEX_W + 10, y - WORLD_INDEX_H - offset, Tools.LEFT_TOP);
				//# }
				//#else
				if (x > (AbstractGameScreen.SCREEN_WIDTH >> 2) * 3) {
					offset = 300 - AbstractGameScreen.SCREEN_WIDTH;
				}
				g.drawImage(img_world_map, 0 - offset, 0, Tools.LEFT_TOP);
				if (img_world_index != null) {
					g.setClip(x - offset, y - WORLD_INDEX_H, WORLD_INDEX_W, WORLD_INDEX_H);
					g.drawImage(img_world_index, x - m_world_index_frame * WORLD_INDEX_W - offset, y - WORLD_INDEX_H, Tools.LEFT_TOP);
				}
				//#endif
			}
			UITools.drawWindowSoftkey(g, UITools.BUTTON_INDEX_XUNLU, UITools.BUTTON_INDEX_FANHUI);// 绘制左右软键
		}
	}

	protected void keyLogic() {
		switch (m_state) {
			case STATUS_NPC_LIST:
				break;
			case STATUS_SCENE_MAP:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					if (GameManager.getInstance().m_role.isAliveStatus()) {
						if (m_scene_map_npc != null && (m_scene_map_page + m_scene_map_index) < m_scene_map_npc.size()) {
							final Function func = (Function)m_scene_map_npc.elementAt(m_scene_map_page + m_scene_map_index);
							if (func.m_id_utf != null) {
								final UIMessageBox mb = (UIMessageBox)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MESSAGEBOX);
								mb.setMessage("是否寻路到" + func.m_name + "?");
								mb.addListener(new UIListener() {
									public void actionPerformed() {
										if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
												|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
											GameManager.getInstance().m_game_message.sendScenePathfinding(func.m_id_utf);
											UIManager.getInstance().removeWindow(mb);
										} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
											UIManager.getInstance().removeWindow(mb);
										}
									}
								});
							} else {
								GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "寻路[" + func.m_name + "]的key为空!");
							}
						}
					}
				} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIAbstractWindow win = UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_NPC);
					if (win != null) {
						UIManager.getInstance().removeWindow(this);
					}
				} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
					if (m_scene_map_npc != null && m_scene_map_npc.size() > 1) {
						byte[] result = UITools.keyPressedIndexPage(m_scene_map_index, m_scene_map_page,
								m_scene_map_npc.size(), UITools.AMOUNT_SUBCOAT_NT_CONTENT, UITools.OPERATION_MINUS);
						m_scene_map_index = result[UITools.KPIP_INDEX];
						m_scene_map_page = result[UITools.KPIP_PAGE];
					}
				} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
					if (m_scene_map_npc != null && m_scene_map_npc.size() > 1) {
						byte[] result = UITools.keyPressedIndexPage(m_scene_map_index, m_scene_map_page,
								m_scene_map_npc.size(), UITools.AMOUNT_SUBCOAT_NT_CONTENT, UITools.OPERATION_ADD);
						m_scene_map_index = result[UITools.KPIP_INDEX];
						m_scene_map_page = result[UITools.KPIP_PAGE];
					}
				}
				m_world_index_frame = ++m_world_index_frame >= WORLD_INDEX_AMOUNT ? 0 : m_world_index_frame;
				break;
			case STATUS_WORLD_MAP:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					if (m_is_area_map) {
						if (GameManager.getInstance().m_role.isAliveStatus()) {
							final UIMessageBox mb = (UIMessageBox)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MESSAGEBOX);
							final String key = SCENE_MAP_KEY[m_world_map_index][m_area_map_index];
							mb.setMessage("传送到" + SCENE_MAP_NAME[m_world_map_index][m_area_map_index] + "需要消耗神行符文一枚,是否传送?");
							mb.addListener(new UIListener() {
								public void actionPerformed() {
									if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
											|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
										GameManager.getInstance().m_game_message.sendSceneTransfer(key);
										UIManager.getInstance().removeWindow(mb);
									} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
										UIManager.getInstance().removeWindow(mb);
									}
								}
							});
						}
					} else {
						setAreaMap();
					}
				} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIAbstractWindow win = UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_NPC);
					if (m_is_area_map) {
						int save = m_world_map_index;
						initWorldMap();
						m_world_map_index = save;
						registerTouch();
					} else {
						if (win != null) {
							UIManager.getInstance().removeWindow(this);
						}
					}
				} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
					if (m_is_area_map) {
						m_area_map_index = --m_area_map_index < 0 ? (AREA_MAP_XY[m_world_map_index].length >> 1) - 1 : m_area_map_index;
					} else {
						m_world_map_index = WORLD_MAP_LINKED[m_world_map_index][WORLD_MAP_DIR_UP];
					}
				} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
					if (m_is_area_map) {
						m_area_map_index = ++m_area_map_index >= (AREA_MAP_XY[m_world_map_index].length >> 1) ? 0 : m_area_map_index;
					} else {
						m_world_map_index = WORLD_MAP_LINKED[m_world_map_index][WORLD_MAP_DIR_DOWN];
					}
				} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
					if (m_is_area_map) {
						m_area_map_index = --m_area_map_index < 0 ? (AREA_MAP_XY[m_world_map_index].length >> 1) - 1 : m_area_map_index;
					} else {
						m_world_map_index = WORLD_MAP_LINKED[m_world_map_index][WORLD_MAP_DIR_LEFT];
					}
				} else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
					if (m_is_area_map) {
						m_area_map_index = ++m_area_map_index >= (AREA_MAP_XY[m_world_map_index].length >> 1) ? 0 : m_area_map_index;
					} else {
						m_world_map_index = WORLD_MAP_LINKED[m_world_map_index][WORLD_MAP_DIR_RIGHT];
					}
				}
				m_world_index_frame = ++m_world_index_frame >= WORLD_INDEX_AMOUNT ? 0 : m_world_index_frame;
				break;
		}
	}
	/**
	 * 绘制场景地图上的NPC列表
	 * @param g
	 */
	private void drawSceneMap(Graphics g) {
		UITools.drawWindowBackgroud(g);//绘制背景
		int offsetW = 0;
		if (m_scene_map_npc != null && m_scene_map_npc.size() > UITools.AMOUNT_SUBCOAT_NT_CONTENT) {
			offsetW = UITools.W_SCROLL_BAR;
			UITools.drawScrollBar(g, UITools.X_SUBCOAT_NT + UITools.W_SUBCOAT_NT - offsetW + 8,
					UITools.Y_SUBCOAT_NT, UITools.H_SUBCOAT_NT,
					(m_scene_map_page + m_scene_map_index) * 100 / (m_scene_map_npc.size() - 1));
		}
		UITools.drawWindowSubcoat(g,//内层背景
				UITools.X_SUBCOAT_NT, UITools.Y_SUBCOAT_NT,
				UITools.W_SUBCOAT_NT - offsetW, UITools.H_SUBCOAT_NT);
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		for (int i = 0; i < UITools.AMOUNT_SUBCOAT_NT_CONTENT; i++) {
//			if (i % 2 == 0) {
//				UITools.drawColorFillRect(g,
//						UITools.X_SUBCOAT_NT + (UITools.H_SUBCOAT_SIDE >> 1), UITools.Y_SUBCOAT_NT + (UITools.H_SUBCOAT_SIDE >> 1) + i * UITools.H_SINGLE_BAR,
//						UITools.W_SUBCOAT_NT - UITools.H_SUBCOAT_SIDE - offsetW, UITools.H_SINGLE_BAR, UIManager.getPaletteColor(UIPalette.COLOR_CBD_DEEP));
//			} else {
//				UITools.drawColorFillRect(g,
//						UITools.X_SUBCOAT_NT + (UITools.H_SUBCOAT_SIDE >> 1), UITools.Y_SUBCOAT_NT + (UITools.H_SUBCOAT_SIDE >> 1) + i * UITools.H_SINGLE_BAR,
//						UITools.W_SUBCOAT_NT - UITools.H_SUBCOAT_SIDE - offsetW, UITools.H_SINGLE_BAR, UIManager.getPaletteColor(UIPalette.COLOR_CBD_LIGHT));
//			}
			if (m_scene_map_npc != null && m_scene_map_page + i < m_scene_map_npc.size()) {
				Function func = (Function)m_scene_map_npc.elementAt(m_scene_map_page + i);
				int x = UITools.X_SUBCOAT_NT + UITools.GAP_LEFT;
				int y = UITools.Y_SUBCOAT_NT + UITools.GAP_UP + i * UITools.H_SINGLE_BAR;
				int color = UIManager.getPaletteColor(UIPalette.COLOR_WORD_NOS);
				if (func.m_lv > 0) {
					if (func.m_lv > 0 && func.m_lv < 5) {
						int tw = GameScene.s_img_f_icon[func.m_lv - 1].getWidth();
						drawIcon(g, func.m_lv, x, y + (UITools.H_SINGLE_BAR >> 1), Tools.LEFT_VCENTER);
						if (func.m_status > 0) {
							drawSceneMapNPC(g, func.m_status, x + tw, y + (UITools.H_SINGLE_BAR >> 1));
							UITools.drawColorString(g, func.m_name, x + tw + 16, y, color, Tools.LEFT_TOP);
						} else {
							UITools.drawColorString(g, func.m_name, x + tw, y, color, Tools.LEFT_TOP);
						}
					}
				} else {
					if (func.m_status > 0) {
						drawSceneMapNPC(g, func.m_status, x, y + (UITools.H_SINGLE_BAR >> 1));
						UITools.drawColorString(g, func.m_name, x + 16, y, color, Tools.LEFT_TOP);
					} else {
						UITools.drawColorString(g, func.m_name, x, y, color, Tools.LEFT_TOP);
					}
				}
				if (func.m_type == AbstractGameActor.ACTOR_TYPE_NPC) {
					UITools.drawColorString(g, "NPC", x + UITools.W_SUBCOAT_NT - offsetW - 8, y, color, Tools.RIGHT_TOP);
				} else if (func.m_type == AbstractGameActor.ACTOR_TYPE_GATE) {
					UITools.drawColorString(g, "传送门", x + UITools.W_SUBCOAT_NT - offsetW - 8, y, color, Tools.RIGHT_TOP);
				} else if (func.m_type == AbstractGameActor.ACTOR_TYPE_GATHERING) {
					UITools.drawColorString(g, "互动", x + UITools.W_SUBCOAT_NT - offsetW - 8, y, color, Tools.RIGHT_TOP);
				} else if (func.m_type == AbstractGameActor.ACTOR_TYPE_MONSTER) {
					UITools.drawColorString(g, "怪物", x + UITools.W_SUBCOAT_NT - offsetW - 8, y, color, Tools.RIGHT_TOP);
				}
			}
		}
		UITools.drawSelectBox(g, UITools.X_SUBCOAT_NT,
				UITools.Y_SUBCOAT_NT + (UITools.H_SUBCOAT_SIDE >> 1) + m_scene_map_index * UITools.H_SINGLE_BAR, 
				UITools.W_SUBCOAT_NT - offsetW, UITools.H_SINGLE_BAR);

		
		UITools.drawTitle(g, "场景信息");// 绘制标题
		UITools.drawWindowSoftkey(g, UITools.BUTTON_INDEX_XUNLU, UITools.BUTTON_INDEX_FANHUI);// 绘制左右软键
	}
	
	private void drawIcon(Graphics g, int id, int x, int y, int anchor) {
//		AbstractGameScreen.drawRegion(g, GameScene.s_img_icon,
//				(id % GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[0],
//				(id / GameScene.SIZE_IMG_ICON[2]) * GameScene.SIZE_IMG_ICON[1],
//				GameScene.SIZE_IMG_ICON[0], GameScene.SIZE_IMG_ICON[1], 0, x, y, anchor);
		
		g.drawImage(GameScene.s_img_f_icon[id - 1], x, y, anchor);
	}
	
	private void drawSceneMapNPC(Graphics g, byte status, int x, int y) {
		switch (status) {
			case ActorNPC.HEAD_STATE_YELLOW_QUESTION_MARK:// 1黄问号
				g.drawImage(GameManager.getInstance().img_head_status[ActorNPC.IMG_HS_Y_QUESTION_MARK], x, y, Tools.LEFT_VCENTER);
				break;
			case ActorNPC.HEAD_STATE_BLUE_QUESTION_MARK:// 2蓝问号
				g.drawImage(GameManager.getInstance().img_head_status[ActorNPC.IMG_HS_B_QUESTION_MARK], x, y, Tools.LEFT_VCENTER);
				break;
			case ActorNPC.HEAD_STATE_YELLOW_EXCLAMATION_MARK:// 4黄叹号
				g.drawImage(GameManager.getInstance().img_head_status[ActorNPC.IMG_HS_Y_EXCLAMATION_MARK], x, y, Tools.LEFT_VCENTER);
				break;
			case ActorNPC.HEAD_STATE_BLUE_EXCLAMATION_MARK:// 8蓝叹号
				g.drawImage(GameManager.getInstance().img_head_status[ActorNPC.IMG_HS_B_EXCLAMATION_MARK], x, y, Tools.LEFT_VCENTER);
				break;
			case ActorNPC.HEAD_STATE_GRAY_QUESTION_MARK:// 16灰问号
				g.drawImage(GameManager.getInstance().img_head_status[ActorNPC.IMG_HS_G_QUESTION_MARK], x, y, Tools.LEFT_VCENTER);
				break;
		}
	}
	/**
	 * 读取NPC互动任务
	 * @param dis
	 */
	public void recvNPCInteract(DataInputStream dis) throws IOException
	{
		m_read_spell_type = dis.readByte();
		Tools.debugPrintln("读条类型 : " + m_read_spell_type);
		int role_act_id = dis.readInt();
		Tools.debugPrintln("玩家动作ID : " + role_act_id);
		int npc_act_id = dis.readInt();
		Tools.debugPrintln("NPC动作ID : " + npc_act_id);
		int time = dis.readInt();
		Tools.debugPrintln("互动时间 : " + time);
		String msg = dis.readUTF();
		Tools.debugPrintln("互动信息 : " + msg);
		GameManager.getInstance().m_role.stay(GameManager.getInstance().m_role.m_direct);
		GameManager.getInstance().m_role.setAction(role_act_id, true);
		if (GameManager.getInstance().m_role.m_targetActor != null) {
			GameManager.getInstance().m_role.m_targetActor.setAction(npc_act_id, true);
		}
		GameManager.getInstance().m_role.startCasting(time * GameManager.FRAME_PER_SECOND);
		GameManager.getInstance().m_role.startCastingDescription(msg);
		((GameScene) GameManager.getInstance().m_scene).startNPCInteract(time * GameManager.FRAME_PER_SECOND);
	}

	/**
	 * 读取NPC列表信息
	 * @param dis
	 * @throws IOException
	 */
	public void recvNPCList(DataInputStream dis) throws IOException
	{
		short state = dis.readShort();
		Tools.debugPrintln("state = " + state);
//		String info = dis.readUTF();
//		Tools.debugPrintln("info = " + info);
		if (state == 0) {
			Tools.debugPrintln("读取NPC信息失败!");
		}
		else if (state == 2) {
//			String key = dis.readUTF();
			long id = dis.readLong();
			if (id > 0) {
				GameManager.getInstance().m_game_message.unlockNetwork();
//				GameManager.getInstance().m_game_message.sendScenePathfinding(key);
				ActorNPC npc = ((GameScene)GameManager.getInstance().m_scene).getNPCByID(id);
				if (npc != null) {
					GameManager.getInstance().m_role.findPathToTarget(npc);
				}
				Tools.debugPrintln("距离过远寻路到 : " + id);
			} else {
				Tools.debugPrintln("距离过远id为0!");
			}
		}
		else {
			m_npc_name = dis.readUTF();
			m_npc_dialog = dis.readUTF();
			String headUrl = dis.readUTF();
			byte taskListSize = dis.readByte();// /任务列表长度
			Tools.debugPrintln("name = " + m_npc_name);
			Tools.debugPrintln("dialog = " + m_npc_dialog);
			Tools.debugPrintln("headUrl = " + headUrl);
			Tools.debugPrintln("taskList size = " + taskListSize);
			m_npc_task = null;
			if (taskListSize > 0) {
				m_npc_task = new Vector();
				for (int i = 0; i < taskListSize; i++) {
					Task task = new Task();
					String taskKey = dis.readUTF();// 任务ID
					String taskName = dis.readUTF();// 任务名称
					byte taskState = dis.readByte();// 任务状态
					byte type = dis.readByte();// 任务类型
					task.m_key = taskKey;
					task.m_name = taskName;
					task.m_status = taskState;
					task.m_type = type;
					Tools.debugPrintln("taskId[" + i + "].taskID = " + taskKey);
					Tools.debugPrintln("taskId[" + i + "].taskName = " + taskName);
					Tools.debugPrintln("taskId[" + i + "].taskState = " + taskState);
					m_npc_task.addElement(task);
				}
			}
			byte funListSize = dis.readByte();// 功能列表长度
			Tools.debugPrintln("funList size = " + funListSize);
			m_npc_function = null;
			if (funListSize > 0) {
				m_npc_function = new Vector();
				for (int i = 0; i < funListSize; i++) {
					Function function = new Function();
					function.m_name = dis.readUTF();// 功能名称
					function.m_instruct = dis.readInt();// 功能指令ID
					function.m_id_utf = dis.readUTF();// 功能附带数据ID
					Tools.debugPrintln("funName[" + i + "].funName = " + function.m_name);
					Tools.debugPrintln("funName[" + i + "].instruct = " + function.m_instruct);
					Tools.debugPrintln("funName[" + i + "].id = " + function.m_id_utf);
					m_npc_function.addElement(function);
				}
			}
			UITaskWindow taskwindow = (UITaskWindow)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_TASK);
			if (taskwindow != null) {
				UIManager.getInstance().removeWindow(taskwindow);
			}
			UIMenu menu = (UIMenu)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MENU_LR);
			if (menu != null) {
				UIManager.getInstance().removeWindow(menu);
			}
			m_win_npc_list = (UIDialogMenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU);
			updateNPCListData();
			setWindowStatus(STATUS_NPC_LIST);
			GameManager.getInstance().m_role.stay(GameManager.getInstance().m_role.m_direct);
		}
	}
	
	/**
	 * 读取场景地图
	 * @param dis
	 */
	public void recvSceneMap(DataInputStream dis) throws IOException
	{
		byte size = dis.readByte();
		Tools.debugPrintln("读取场景地图NPC长度 : " + size);
		if (m_scene_map_npc != null) {
			m_scene_map_npc.removeAllElements();
			m_scene_map_npc = null;
		}
		if (size > 0) {
			m_scene_map_page = 0;
			m_scene_map_index = 0;
			m_scene_map_npc = new ArrayList();
			for (byte i = 0; i < size; i++) {
				Function func = new Function();
				func.m_type = dis.readByte();
				func.m_id_utf = dis.readUTF();
				func.m_name = dis.readUTF();
				func.m_status = dis.readByte();//任务状态
				func.m_lv = dis.readByte();//功能图标
				m_scene_map_npc.addElement(func);
				Tools.debugPrintln("第" + (i + 1) + "个NPC type : "
						+ func.m_type + ", key : " + func.m_id_utf
						+ ", name : " + func.m_name + ", status : " + func.m_lv);
			}
			UIAbstractWindow menu = UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_MENU_LR);
			if (menu != null) {
				UIManager.getInstance().removeWindow(menu);
			}
			setWindowStatus(STATUS_SCENE_MAP);
			UIAbstractWindow win = UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_NPC);
			if (win == null) {
				UIManager.getInstance().addWindow(this);
			}
		} else {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "当前场景无NPC!");
		}
	}

	
//	/**
//	 * 互动任务打断
//	 * @param dis
//	 * @throws IOException
//	 */
//	public void recvNPCInteractBreak(DataInputStream dis) throws IOException
//	{
//		((GameScene) GameManager.getInstance().m_scene).endNPCInteract();
//		GameManager.getInstance().m_role.stopCasting();
//		GameManager.getInstance().m_role.stopCastingDescription();
//	}

	public void updateNPCListData()
	{
		if (m_win_npc_list != null) {
			String[] npclistData = getNPCListData();
			m_win_npc_list.setContents(m_npc_name, m_npc_dialog, npclistData);
			m_win_npc_list.addListener(getNPCListListener());
		}
	}

	/**
	 * NPC列表
	 * @param win
	 */
	public UIListener getNPCListListener()
	{
		if (m_npc_task == null) {
			Tools.debugPrintln("getNPCListListener m_npc_task is null!");
		}
		if (m_npc_function == null) {
			Tools.debugPrintln("getNPCListListener m_npc_function is null!");
		}
		if (m_npc_task == null && m_npc_function == null) {// 没有任务列表和功能列表
			UIListener listener = new UIListener() {
				public void actionPerformed() {
					if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
						UIManager.getInstance().removeWindow(m_win_npc_list);
					}
				}
			};
			return listener;
		} else {// 有任务列表或者功能列表
			UIListener listener = new UIListener() {
				public void actionPerformed() {
					if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
						UIManager.getInstance().removeWindow(m_win_npc_list);
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
							|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
						int index = m_win_npc_list.getCurrentIndex();
						Tools.debugPrintln("NPC列表选择index : " + index);
						if (m_npc_task == null) {
							Function func = (Function) m_npc_function.elementAt(index);
							if (func != null) {
								GameManager.getInstance().m_game_message.sendFunction(func.m_instruct, func.m_id_utf);
							}
//							UIManager.getInstance().removeWindow(m_win_npc_list);
						}
						else {
							if (index >= m_npc_task.size()) {
								Function func = (Function) m_npc_function.elementAt(index - m_npc_task.size());
								if (func != null) {
									GameManager.getInstance().m_game_message.sendFunction(func.m_instruct, func.m_id_utf);
								}
//								UIManager.getInstance().removeWindow(m_win_npc_list);
							}
							else {
								Task task = (Task) m_npc_task.elementAt(index);
								m_npc_operate_id = index;
								if (task != null) {
									GameManager.getInstance().m_game_message.sendNPCTaskView(task.m_key);
									GameManager.getInstance().m_game_message.lockNetwork();
								}
							}
						}
					}
				}
			};
			return listener;
		}
	}

	/**
	 * 得到NPC列表数据
	 * @return
	 */
	public String[] getNPCListData()
	{
		int len = 0;
		String[] npcList = null;
		if (m_npc_task != null) {
			len += m_npc_task.size();
		}
		if (m_npc_function != null) {
			len += m_npc_function.size();
		}
		if (len > 0) {
			npcList = new String[len];
			int k = 0;
			if (m_npc_task != null) {
				for (int i = 0; i < m_npc_task.size(); i++) {
					Task task = (Task) m_npc_task.elementAt(i);
					npcList[k] = "<mark c=" + task.TASK_NAME_COLOR_STR[task.m_status] + ">" + task.TASK_STATUS[task.m_status] + "</mark>" + task.m_name;
					Tools.debugPrintln("添加NPC列表 : " + npcList[k]);
					k++;
				}
			}
			if (m_npc_function != null) {
				for (int i = 0; i < m_npc_function.size(); i++) {
					Function func = (Function) m_npc_function.elementAt(i);
					npcList[k] = func.m_name;
					Tools.debugPrintln("添加NPC列表 : " + npcList[k]);
					k++;
				}
			}
		}
		return npcList;
	}
	/**
	 * 初始化世界地图
	 */
	public void initWorldMap() {
		img_world_map = null;
		img_world_map = Tools.createImage(RES_MAP_PATH + RES_WORLD_MAP + RES_END);
		if (img_world_index == null) {
			img_world_index = Tools.createImage(RES_MAP_PATH + RES_WORLD_INDEX + RES_END);
			WORLD_INDEX_W = (byte)(img_world_index.getWidth() / WORLD_INDEX_AMOUNT);
			WORLD_INDEX_H = (byte)img_world_index.getHeight();
			m_world_index_frame = 0;
		}
		m_world_map_index = 0;
		m_area_map_index = 0;
		setWindowStatus(STATUS_WORLD_MAP);
		m_is_area_map = false;
	}
	public void setAreaMap() {
		if (AREA_MAP_XY[m_world_map_index] != null && AREA_MAP_XY[m_world_map_index].length > 0) {
			img_world_map = null;
			img_world_map = Tools.createImage(RES_MAP_PATH + RES_AREA_MAP + (m_world_map_index + 1) + RES_END);
			m_is_area_map = true;
		} else {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "此区域暂未开放!");
		}
		registerTouch();
	}
	/******************* 常量 *********************/
	public final byte STATUS_NPC_LIST = 0;
	public final byte STATUS_SCENE_MAP = 1;
	public final byte STATUS_WORLD_MAP = 2;
	
//	private final int WORLD_MAP_AMOUNT = 11;//区域总数
	private final int[] WORLD_MAP_XY =
	{
		255, 200,//泰山秘境，原泰山,0
		40, 80,//瑶池仙境，原瑶池,1
		165, 80,//海外仙山，原蓬莱,2
		160, 170,//西都长安，原长安,3
		100, 250,//阎罗殿，原地府,4
		/////////////////////老的
	//	53, 73,//昆仑,0
	//	261, 126,//泰山,1
	//	60, 210,//洞庭,2
	//	142, 40,//瑶池,3
	//	248, 60,//蓬莱,4
	//	115, 263,//黄泉,5
	//	123, 169,//长安,6
	//	210, 230,//地府,7
	//	186, 160,//玉清,8
		/////////////////////最老的
//		123, 163,//仙缘,0
//		57, 51,//昆仑,1
//		142, 40,//瑶池,2
//		249, 45,//泰山,3
//		209, 96,//洛阳,4
//		50, 108,//长安,5
//		155, 117,//紫薇,6
//		86, 192,//阎罗殿,7
//		191, 162,//玉清,8
//		270, 173,//蓬莱,9
//		36, 213,//洞庭,10
//		103, 272,//黄泉,11
//		204, 226,//丰都,12
	};
	
	public final int[][] WORLD_MAP_LINKED =
	{
		{2, 4, 3, 3},//泰山,1 0
		{4, 4, 2, 2},//瑶池,3 1
		{4, 3, 1, 1},//蓬莱,4 2
		{2, 4, 0, 0},//长安,6 3
		{1, 1, 0, 3},//地府（阎罗殿）,7 4
		///////////////////////老的
//		{2, 2, 4, 3},//昆仑,0
//		{4, 7, 8, 2},//泰山,1
//		{0, 0, 1, 5},//洞庭,2
//		{5, 6, 0, 4},//瑶池,3
//		{7, 1, 3, 0},//蓬莱,4
//		{6, 3, 2, 7},//黄泉,5
//		{3, 5, 2, 8},//长安,6
//		{8, 4, 5, 2},//地府（阎罗殿）,7
//		{4, 7, 6, 1},//玉清,8
		/////////////////////////最老的
//		{6, 11, 7, 8},//仙缘,0
//		{10, 5, 3, 2},//昆仑,1
//		{11, 6, 1, 3},//瑶池,2
//		{12, 4, 2, 1},//泰山,3
//		{3, 9, 6, 5},//洛阳,4
//		{1, 10, 4, 7},//长安,5
//		{2, 0, 7, 8},//紫薇,6
//		{5, 11, 10, 0},//阎罗殿,7
//		{4, 12, 0, 9},//玉清,8
//		{4, 12, 8, 5},//蓬莱,9
//		{5, 11, 12, 7},//洞庭,10
//		{7, 2, 10, 12},//黄泉,11
//		{8, 3, 11, 10},//丰都,12
	};
	private final byte WORLD_MAP_DIR_UP = 0;
	private final byte WORLD_MAP_DIR_DOWN = 1;
	private final byte WORLD_MAP_DIR_LEFT = 2;
	private final byte WORLD_MAP_DIR_RIGHT = 3;
	
	private int[][] AREA_MAP_XY =
	{
		{135,40, 133,120, 110,77, 67,112, 25,100},//1泰山	明霞峰,泰山麓,天齐峰,碧霞峰,逸水峰
		{133,40, 140,100, 110,65, 110,130, 68,115, 45,98, 11,58},//3瑶池7	瑶台,落宝崖，迎仙台,蟠桃园,瑶池秘境,幻心池,通天路
		{136,37, 132,100, 111,51, 110,120, 70,112, 25,125},//4蓬莱6	幻雾海,落星崖,蓬莱境,凤栖林,三星居,神龟原
		{56,40, 100,42, 136,70, 109,120, 47,126, 21,78},//6长安6	太极宫,渭水,东市,芙蓉园,慈恩寺,西市
		{18,51, 33,118, 62,75, 90,48, 90,122, 135,56, 126,116},//7阎罗殿7	血污池,平等殿,森罗狱,无间狱,生死道,阎罗殿,转轮殿


		/////////////////老的
//		{147,145, 103,124, 66,90, 141,68, 32,134},//0昆仑5	玉龙村,射日岭,昆仑雪原,凝碧林,西海
//		{52,75, 93,109, 39,143, 136,146, 146,74},//1泰山5	明霞谷,天齐殿,岱宗坊,碧霞祠,日观峰
//		{44,68, 39,146, 90,90, 126,151, 141,78},//2洞庭5	洞庭乡,洞庭山,湘妃祠,灵虚府,南岳庙
//		{126,142, 150,80, 40,140, 95,62, 37,66, 75,121},//3瑶池6	迎真崖,百草园,浴天台,瑶台,蟠桃园,青鸾殿
//		{57,137, 90,66, 31,95, 132,80, 152,146, 104,154},//4蓬莱6	蓬莱阁,凌虚度,洞虚府,神木林,奇兽崖,东华台
//		{28,84, 84,100, 148,124, 54,139, 107,153, 128,71},//5黄泉6	望乡台,孟婆庄,点鬼台,鬼门关,奈何桥,三途川
//		{69,68, 113,63, 150,91, 122,147, 60,154, 32,97},//6长安6	太极宫,渭水,东市,芙蓉园,慈恩寺,西市
//		{30,77, 73,100, 102,149, 147,81, 44,144, 101,72, 138,142},//7阎罗殿7	血污池,森罗狱,生死道,阎罗殿,平等殿,无间狱,转轮殿
//		{},//8玉清0
	};
	private final String[][] SCENE_MAP_KEY =
	{
//////////////////////////新的
			//泰山秘境：
			{"lh_ts_mxf",//明霞峰
			"lh_ts_tsl",//泰山麓
			"lh_ts_tqf",//天齐峰
			"lh_ts_bxf",//碧霞峰
			"lh_ts_ysf"},//逸水峰
			
			//瑶池仙境：
			{"lh_yc_yt",//瑶台
			"lh_yc_lby",//落宝崖
			"lh_yc_yxt",//迎仙台
			"lh_yc_pty",//蟠桃园
			"lh_yc_ycmj",//瑶池秘境
			"lh_yc_hxc",//幻心池
			"lh_yc_ttl"},//通天路

			//海外仙山:
			{"lh_pl_hwh",//幻雾海
			"lh_pl_lxy",//落星崖
			"lh_pl_plj",//蓬莱境
			"lh_pl_fql",//凤栖林
			"lh_pl_sxj",//三星居
			"lh_pl_sgy"},//神龟原

			//长安：
			{"changa_tjg",//太极宫
			"changa_ws",//渭水
			"changa_ds",//东市
			"changa_fry",//芙蓉园
			"changa_ces",//慈恩寺
			"changa_xs"},//西市
			
			//阎罗殿：
			{"yanl_xwc",//血污池
			"yanl_pdd",//平等殿
			"yanl_sly",//森罗狱
			"yanl_wjy",//无间狱
			"yanl_ssd",//生死道
			"yanl_yld",//阎罗殿
			"yanl_zld"},//转轮殿
			
			//玉清:
			{},
			
			//////////////////////////老的
//			//仙缘：
//			{"xins_xys",//仙缘山
//			"xins_xyc",//仙缘村
//			"xins_hbc"},//幻波池
//
//			//昆仑：
//			{"kunl_ylc",//玉龙村
//			"kunl_srl",//射日岭
//			"kunl_klxy",//昆仑雪原
//			"kunl_nbl",//凝碧林
//			"kunl_xh"},//西海
//
//			//瑶池：
//			{"yaoc_yzy",//迎真崖
//			"yaoc_bcy",//百草园
//			"yaoc_ytt",//浴天台
//			"yaoc_yt",//瑶台
//			"yaoc_pty",//蟠桃园
//			"yaoc_qld"},//青鸾殿
//			
//			//泰山：
//			{"tais_mxg",//明霞谷
//			"tais_tqd",//天齐殿
//			"tais_dzf",//岱宗坊
//			"tais_bxc",//碧霞祠
//			"tais_rgf"},//日观峰
//
//			//洛阳：
//			{"luoy_bms",//白马寺
//			"luoy_xy",//西苑
//			"luoy_lyg",//洛阳宫
//			"luoy_ns",//南市
//			"luoy_bs",//北市
//			"luoy_ls"},//洛水
//			
//			
//			//长安：
//			{"changa_tjg",//太极宫
//			"changa_ws",//渭水
//			"changa_ds",//东市
//			"changa_fry",//芙蓉园
//			"changa_ces",//慈恩寺
//			"changa_xs"},//西市
//
//			//紫薇:
//			{},
//			
//			//阎罗殿：
//			{"yanl_xwc",//血污池
//			"yanl_sly",//森罗狱
//			"yanl_ssd",//生死道
//			"yanl_yld",//阎罗殿
//			"yanl_pdd",//平等殿
//			"yanl_wjy",//无间狱
//			"yanl_zld"},//转轮殿
//			
//			//玉清:
//			{},
//			
//			//蓬莱:
//			{"pengl_plg",
//			"pengl_lxd",
//			"pengl_dxf",
//			"pengl_sml",
//			"pengl_qsy",
//			"pengl_dht"},
//			
//			//洞庭:
//			{"dongt_dtx",
//			"dongt_dts",
//			"dongt_xfc",
//			"dongt_lxf",
//			"dongt_nym"},
//			
//			//黄泉：
//			{"huangq_wxt",//望乡台
//			"huangq_mpz",//孟婆庄
//			"huangq_dgt",//点鬼台
//			"huangq_gmg",//鬼门关
//			"huangq_nhq",//奈何桥
//			"huangq_stc"},//三途川
//
//			//丰都城：
//			{"fengd_fdf",//丰都府
//			"fengd_bpt",//剥皮亭
//			"fengd_gs",//鬼市
//			"fengd_xs",//血市
//			"fengd_hsh",//黑水河
//			"fengd_dzt"},//地藏台
	};
	private final String[][] SCENE_MAP_NAME =
	{
		//////////////////////新的
		//泰山：
		{"明霞峰", "泰山麓", "天齐峰", "碧霞峰", "逸水峰"},
		//瑶池：
		{"瑶台", "落宝崖", "迎仙台", "蟠桃园","瑶池秘境","幻心池","通天路"},
		//蓬莱:
		{"幻雾海", "落星崖", "蓬莱境","凤栖林", "三星居", "神龟原"},
		//长安：
		{"太极宫", "渭水", "东市", "芙蓉园", "慈恩寺", "西市"},
		//阎罗殿：
		{"血污池", "平等殿", "森罗狱", "无间狱", "生死道", "阎罗殿", "转轮殿"},
		//玉清:
		{},
		//////////////////////老的
//			//仙缘：
//			{"仙缘山",//仙缘山
//			"仙缘村",//仙缘村
//			"幻波池"},//幻波池
//
//			//昆仑：
//			{"玉龙村",//玉龙村
//			"射日岭",//射日岭
//			"昆仑雪原",//昆仑雪原
//			"凝碧林",//凝碧林
//			"西海"},//西海
//
//			//瑶池：
//			{"迎真崖",//迎真崖
//			"百草园",//百草园
//			"浴天台",//浴天台
//			"瑶台",//瑶台
//			"蟠桃园",//蟠桃园
//			"青鸾殿"},//青鸾殿
//			
//			//泰山：
//			{"明霞谷",//明霞谷
//			"天齐殿",//天齐殿
//			"岱宗坊",//岱宗坊
//			"碧霞祠",//碧霞祠
//			"日观峰"},//日观峰
//
//			//洛阳：
//			{"白马寺",//白马寺
//			"西苑",//西苑
//			"洛阳宫",//洛阳宫
//			"南市",//南市
//			"北市",//北市
//			"洛水"},//洛水
//			
//			
//			//长安：
//			{"太极宫",//太极宫
//			"渭水",//渭水
//			"东市",//东市
//			"芙蓉园",//芙蓉园
//			"慈恩寺",//慈恩寺
//			"西市"},//西市
//
//			//紫薇:
//			{},
//			
//			//阎罗殿：
//			{"血污池",//血污池
//			"森罗狱",//森罗狱
//			"生死道",//生死道
//			"阎罗殿",//阎罗殿
//			"平等殿",//平等殿
//			"无间狱",//无间狱
//			"转轮殿"},//转轮殿
//			
//			//玉清:
//			{},
//			
//			//蓬莱:
//			{"蓬莱阁",
//			"凌虚渡",
//			"洞虚府",
//			"神木林",
//			"奇兽崖",
//			"东华台"},
//			
//			//洞庭:
//			{"洞庭乡",
//			"洞庭山",
//			"湘妃祠",
//			"灵虚府",
//			"南岳庙"},
//			
//			//黄泉：
//			{"望乡台",//望乡台
//			"孟婆庄",//孟婆庄
//			"点鬼台",//点鬼台
//			"鬼门关",//鬼门关
//			"奈何桥",//奈何桥
//			"三途川"},//三途川
//
//			//丰都城：
//			{"丰都府",//丰都府
//			"剥皮亭",//剥皮亭
//			"鬼市",//鬼市
//			"血市",//血市
//			"黑水河",//黑水河
//			"地藏台"},//地藏台
	};
	/******************* 窗口 *********************/
	public UIDialogMenu m_win_npc_list = null;
	/******************* 变量 *********************/
	public Vector m_npc_task = null;// NPC界面任务数组
	public Vector m_npc_function = null;// NPC界面功能数组
	public int m_npc_operate_id = 0;//正在操作的id/下标
	public String m_npc_name = null;// 正在操作的名字(NPC名字)
	public String m_npc_dialog = null;// 接收NPC信息时保存的NPC对话
	public byte m_read_spell_type = 0;//读条类型
	
	public ArrayList m_scene_map_npc = null;
	private byte m_scene_map_index = 0;//场景地图下标
	private byte m_scene_map_page = 0;//场景地图页数
	
	private final String RES_MAP_PATH = "/img/worldmap/";
	private final String RES_WORLD_MAP = "worldmap";
	private final String RES_WORLD_INDEX = "worldindex";
	private final String RES_AREA_MAP = "area";
	private final String RES_END = ".png";
	private final byte WORLD_INDEX_AMOUNT = 7;//世界地图总帧数
	private byte WORLD_INDEX_W = 0;
	private byte WORLD_INDEX_H = 0;
	private Image img_world_map = null;
	private Image img_world_index = null;
	private int m_world_map_index = 0;
	private int m_area_map_index = 0;
	private byte m_world_index_frame = 0;//世界地图下标当前帧数
	private boolean m_is_area_map = false;
	/////////////////////////////////////////
//	int[][] worldRect ;
	protected void registerTouch() {
		clearAllRects();
		registerNormalSoft();
		switch (m_state) {
		case STATUS_NPC_LIST:
			break;
		case STATUS_SCENE_MAP:
//			drawSceneMap(g);
			int size = m_scene_map_npc.size();
			int[][] rect = new int[size][];
			for(int i=0;i<size;i++) {
				int x = UITools.X_SUBCOAT_NT + UITools.GAP_LEFT;
				int y = UITools.Y_SUBCOAT_NT + UITools.GAP_UP + i * UITools.H_SINGLE_BAR;
				rect[i] = new int[]{x ,y ,UITools.W_SUBCOAT_NT, UITools.H_SINGLE_BAR};
			}
			initTouchRect(rect);
			break;
		case STATUS_WORLD_MAP:
			if (m_is_area_map) {
				switch(m_world_map_index) {
				case 0:
					initTouchRect(new int[][]{
							{287,74,26,61},
							{287,161,26,61},
							{258,116,23,65},
							{218,149,28,69},
							{176,134,28,69},
					});
					
					break;
				case 1:
					initTouchRect(new int[][]{
							{286,72,21,62},
							{293,139,21,62},
							{264,99,18,62},							
							{259,165,20,62},
							{223,148,21,73},
							{199,133,21,62},
							{169,94,21,62},
					});
					break;
				case 2:
					initTouchRect(new int[][]{
							{286,73,18,62},
							{286,139,21,62},
							{264,91,18,62},	
							{262,162,20,62},
							{221,152,21,73},
							{177,162,21,62},
					});
					break;
				case 3:
					initTouchRect(new int[][]{
							{209,77,21,62},
							{254,92,21,44},
							{291,119,21,44},
							{262,157,21,62},
							{202,166,21,63},
							{171,127,24,44},
					});
					break;
				case 4:
					initTouchRect(new int[][]{
							{171,86,22,62},
							{185,154,22,62},
							{214,110,22,62},
							{242,81,22,62},
							{242,159,22,62},
							{288,90,22,62},
							{278,152,22,62},
					});
					break;
				}
			} else {
				initTouchRect(new int[][]{
						{220,130,77,111},	//泰山
						{0,16,90,117},	//瑶池
						{151,10,92,96},	//蓬莱
						{110,110,95,100},	//长安
						{26,190,85,100},//阎罗殿
						});
			}
			break;
		}
	}

//	{135,40, 133,120, 110,77, 67,112, 25,100},//1泰山	明霞峰,泰山麓,天齐峰,碧霞峰,逸水峰
//	{133,40, 140,100, 110,65, 110,130, 68,115, 45,98, 11,58},//3瑶池7	瑶台,落宝崖，迎仙台,蟠桃园,瑶池秘境,幻心池,通天路
//	{136,37, 132,100, 111,51, 110,120, 70,112, 25,125},//4蓬莱6	幻雾海,落星崖,蓬莱境,凤栖林,三星居,神龟原
//	{56,40, 100,42, 136,70, 109,120, 47,126, 21,78},//6长安6	太极宫,渭水,东市,芙蓉园,慈恩寺,西市
//	{18,51, 33,118, 62,75, 90,48, 90,122, 135,56, 126,116},//7阎罗殿7	血污池,平等殿,森罗狱,无间狱,生死道,阎罗殿,转轮殿
	protected void onTouchRect(int[][] rect, int touchid) {
		switch (m_state) {
		case STATUS_NPC_LIST:
			break;
		case STATUS_SCENE_MAP:
//			drawSceneMap(g);
			if (m_scene_map_index == (byte) touchid) {
				GameTouchManager.keyPressedFire();
			} else {
				m_scene_map_index = (byte) touchid;
			}
			break;
		case STATUS_WORLD_MAP:
			if (m_is_area_map) {
				if (m_area_map_index == touchid) {
					GameTouchManager.keyPressedFire();
				} else {
					m_area_map_index = touchid;
				}
			} else {
				if (m_world_map_index == touchid) {
					GameTouchManager.keyPressedFire();
				} else {
					m_world_map_index = touchid;
				}
			}
			break;
		}
	}

	protected void actionOnStateChanged() {
		registerTouch();
	}
	
	
}
